// pages/register2/register2.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop:0,
    lineList:[
        {
            title:''
        }
    ],
    control_man: "", // 负责人
    control_phone: "", // 负责人电话
  },
  input(e) {
    let {
      type
    } = e.currentTarget.dataset || {}, {
      value
    } = e.detail || {}, data = {};
    data[type] = value;
    this.setData(data)
  },
  // 删除
  delete_(val){
    let { index } = val.currentTarget.dataset || {}, list = this.data.lineList;
    list.splice(index,1)
    this.setData({
      lineList: list
    })    
  },
  // 新增
  add(){
    let list = this.data.lineList;
    list.push({title:'1'})
    this.setData({
      lineList: list
    })
  },
  // 注册
  register(){
    console.log('getCurrentPages', getCurrentPages());
    let page_length = getCurrentPages().length;
    if(page_length < 3)   return wx.$Toast('注册页面出现问题');
    let register_page = getCurrentPages().splice(page_length - 3);
    let [page,page1,page2]=register_page;
    let registeData = getApp().getRegisterData();
    console.log('page',page);
    console.log('page1',page1);
    console.log('page2',page2);
    console.log("输出父页面",page.data)
    let data = {
      type: registeData.type,
      company_name: registeData.company_name,
      organization_code: registeData.organization_code,
      buiss_time_start: registeData.buiss_time_start,
      buiss_time_end: registeData.buiss_time_end,
      company_address: registeData.company_address,
      legal_person: registeData.legal_person,
      legal_phone: registeData.legal_phone,
      legal_card_no: registeData.legal_card_no,
      license_img: registeData.license_img,
      legal_card_pros: registeData.legal_card_pros,
      legal_card_cons: registeData.legal_card_cons,
      control_man: this.data.control_man,
      control_phone: this.data.control_phone,
      lng: wx.getStorageSync('longitude'),
      lat: wx.getStorageSync('latitude'), 
    }
    console.log(data,'mmmmmmmmmmmmmmmmmmmmmmmmm')
    wx.$api.applyCompany(data).then(r=>{
         console.log(r,'ssssssssssssssss')
         if(r.data.code==200){
           wx.$Toast('已提交');
          setTimeout(()=>{
             wx.navigateBack({
               delta:3
             })
          },500)
         }else{
           wx.$Toast(r.data.msg);
           return;
         }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('getCurrentPages', getCurrentPages());
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})